package cn.lisens.jpa.domain;

import javax.persistence.Column;
import javax.persistence.Entity;
import javax.persistence.GeneratedValue;
import javax.persistence.GenerationType;
import javax.persistence.Id;
import javax.persistence.Table;
import javax.persistence.Transient;
import javax.persistence.UniqueConstraint;
import javax.persistence.Version;
import javax.validation.constraints.Size;
import javax.validation.constraints.NotBlank;

import lombok.Data;

@Entity
@Table(name = "person_base", 
       uniqueConstraints = {
           @UniqueConstraint(columnNames = {"idcard"}),
           @UniqueConstraint(columnNames = {"email", "phone"})
       })
@Data
public class PersonBase {
	
	@Id
    @GeneratedValue(strategy = GenerationType.IDENTITY)
    private Long id;
	
	@Column(length = 18, unique = true)
	@NotBlank(message = "身份证号不能为空")
	@Size(max = 50, message = "姓名长度不能超过50个字符")
    private String idcard;
	
	private String fullName;
    
    private String email;
    
    private String phone;
    
    @NotBlank(message = "用户名不能为空")
    @Size(min = 3, max = 20, message = "用户名长度必须在3到20个字符之间")
    private String username;
    
    @Version
    private Integer version;  // 乐观锁字段
    
    @Transient
    private Object refObj;
    
}
